//
//  slidingViewController.m
//
//
//  Created by zhangyuv.
//  Copyright (c) 2013年 yonyou. All rights reserved.
//

#import "@{nameOfClass}.h"
@{importChildHs}
@implementation @{nameOfClass}
@synthesize @{id} = _@{id};
@synthesize parentController = _parentController;
@synthesize currentContainer = _currentContainer;
@synthesize contextDictionary = _contextDictionary;
@synthesize ctx = _ctx;
@{umcontextSynthesize}
@{controllerC}
@{context}
@{addChildSynthesizes}

- (id)initWithParentCtl:(UIViewController*) parentCtl
{
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        if(parentCtl){
            self.parentController = parentCtl;
        }else{
            self.parentController = self;
        }
        _@{id} = _viewObject;
        @{selfView}
        _context = [[UMEntityContext alloc]init];
		_ctx = _context;
    }
	return self;
}
- (void)loadView
{
	[super loadView];
}

- (void)viewDidLoad
{

	AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
	_currentContainer = [appDelegate currentContainer];

	@{initChilds}
	@{addChilds}
	@{setviewDidLoads}
	[super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];
	[SysContext getInstance].CurrentViewController = self;
}

- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated];
	    AppDelegate* appDelegate = [[UIApplication sharedApplication] delegate];
    NSString* result_str = [appDelegate.plugDict objectForKey:@"result"];
    if(result_str){
        [self dataBind:result_str];
    }

	[SysContext getInstance].CurrentViewController = self;
    @{onload}
}

- (void)viewDidUnload
{
	[super viewDidUnload];
}

-(void)onInit{
    [_currentContainer onInit:controllerC];
}
-(void)onLoad{
    [_currentContainer onLoad:controllerC];
}
-(void)onDataBinding{
    //here do databinding
    NSString *context = [_currentContainer getModel:ModelName];
    _contextDictionary = [context objectFromJSONString];
    if(_contextDictionary != nil)
    	[self dataBind:[_contextDictionary JSONString]];
}
-(void)onComplete{
    [_currentContainer onComplete:controllerC];
    
    //common message: {"error":["网络无法连接！"],"warnning":[]}
    NSString *msg = [_currentContainer getMessage];
    //[self dumpMsg:msg];
}
- (void)dataBind:(NSString*)data{
	if(data !=nil){
		@{umcontextCreate}
	}
	@{dataBinds}
}
-(void)reloadDataByAddress:(NSString*)address modelName:(NSString*)moduleName controllerC:(NSString*)controllerCName
{
	ModelName = moduleName;
    controllerC = controllerCName;
    [_currentContainer initController:ModelName];
	[SysContext getInstance].ServiceAddress = address;
    [self onInit];
    [self onLoad];
}
- (void)loadDataByUrlOfServer:(NSString*) url
{
	UMRequest* request = [[UMRequest alloc] init];
	request.url = url;
	UMServerProxy* server = [[UMServerProxy alloc] initWithUMRequest:request];
	[server startAsynchronous];
	server.finishBlock=^(NSData* data){
		_contextDictionary = [data objectFromJSONData];
		if(_contextDictionary){
			[self dataBind:[_contextDictionary JSONString]];
		}
	};

}
@end